#define  _CRT_SECURE_NO_WARNINGS 1
#include"stack.h"

void StackInit(Stack* s)
{
	assert(s);
	s->arr = NULL;
	s->capacity = 0;
	s->top = 0;
}
void StackDestroy(Stack* s)
{
	assert(s);
	free(s->arr);
	s->arr = NULL;
	s->capacity = 0;
	s->top = 0;
}
void StackPush(Stack* s, DataType x)
{
	assert(s);
	if (s->capacity == s->top)
	{
		int newcapacity = s->capacity == 0 ? 4 : s->capacity * 2;
		DataType* tmp = (DataType*)malloc(sizeof(DataType)*newcapacity);
		if (tmp == NULL)
		{
			printf("realloc is fail\n");
			exit(-1);
		}
		s->capacity = newcapacity;
		s->arr = tmp;
	}
	s->arr[s->top] = x;
	s->top++;
}
void StackPush(Stack* s,DataType x)
{
	assert(s);
	if (s->capacity == s->top)
	{
		int newcapacity = s->capacity == 0 ? 4 : s->capacity * 2;
		DataType* tmp = (DataType*)realloc(s->arr, sizeof(DataType) * newcapacity);
		if (tmp == NULL)
		{
			printf("realloc is fail\n");
			exit(-1);
		}
		s->arr = tmp;
		s->capacity = newcapacity;
	}
	s->arr[s->top] = x;
	s->top++;
}
void StackPop(Stack* s)
{
	assert(s);
	assert(!StackEmpty(s));
	s->top--;
}
DataType StackTop(Stack* s)
{
	assert(s);
	assert(!StackEmpty(s));
	return s->arr[s->top - 1];
}
bool StackEmpty(Stack* s)
{
	assert(s);
	return s->top == 0;
}
int StackSize(Stack* s)
{
	assert(s);
	return s->top;
}

struct Stack {
	DataType* arr;
	int capacity;
	int top;
};

int main()
{
	//1.
	struct Stack* s;

	//2.
	Stack* s;
	return 0;
}